function initPage() {
    initInputText();
    initStripeTable();
}

function initStripeTable() {
    $(".stripe tr").mouseover(function () {
        $(this).addClass("over");
    })
        .mouseout(function () {
            $(this).removeClass("over");
        });
    $(".stripe tr:even").addClass("alt");
}

function initTabsCSS() {
    $("ul.tabs li:first").addClass("active");
    $("div.pages div.page:not(:first)").hide();
    $("ul.tabs li").click(function () {
        $(this).addClass("active").siblings("li").removeClass("active");
        $("#" + $(this).attr("page")).show().siblings("div.page").hide();
    });
}

function isValid() {
    var result = true;
    var requireText = "";
    $("input[required], textarea[required], select[required]").each(function () {
        if (result && ((jQuery.trim($(this).val()) == "") || (jQuery.trim($(this).val()) == jQuery.trim($(this).attr("placeHolder"))))) {
            alert($(this).attr("requireText"));
            $(this).focus();
            result = false;
        }
    });

    if (result && ($(".selectable").length > 0) && ($(".selectable[checked]").length == 0)) {
        alert($(this).attr("requireText"));
        result = false;
    }
    return result;
}
/*
 function loadPage(id, url) {
 //alert(id);alert(url); 
 $("#"+id).empty();
 $("#"+id).addClass("loader");
 //$("#"+id).append("Loading...");
 $.ajax({
 type: "get",
 url: url,
 cache: false,
 dataType: 'html',
 error: function() {alert('load page error');},
 success: function(msg) {
 $("#"+id).empty().append(msg);
 //            initPage();
 $("#"+id).removeClass("loader");
 }
 });
 }
 */

function loadTablePage(id, pageIndex, url) {
    $("#" + id).empty().addClass("loader").append("Loading...");
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'html',
        data: {"page": pageIndex},
        error: function (msg) {
            alert("Get data error:" + msg);
        },
        success: function (msg) {
            $("#" + id).empty().append(msg);
            initStripeTable();
            $("#" + id).removeClass("loader");
        }
    });
}
/*
 function postData(id, postUrl, postData, renderUrl)
 {
 $.ajax({
 //cache: true,
 type: "POST",
 url: postUrl,
 data: postData,
 //async: true,
 beforeSend:function(){
 $("#"+id).html("Loading......");
 },
 error: function(request) {
 alert("Connection error");
 },
 success: function(msg) {
 //alert('Data saved: ' + msg);
 $("#"+id).empty();
 $("#"+id).addClass("loader");
 loadPage(id, renderUrl);
 $("#"+id).removeClass("loader");
 }
 });
 }*/

/************login begin*******************************/
//登录处理
function Login(postUrl, postData, renderUrl) {
    if (Check()) {
        //LoginSuccess(postUrl, postData, renderUrl);
        //alert('success');
    }
}

//初期检查 
function Check() {
    //var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;

    if ($("#username").val() == "") {
        alert("Username cann't be empty.");
        //$("#message").html("Username cann't be empty.");
        $("#username").focus();
        $(":submit").attr("disabled", false);
        return false;
    }
    /*  if(! reg.test($("#"+usernameid).val())){
     //alert("please input correct username format.");//请输入正确的用户名格式，为邮件地址
     $("#message").html("please input correct username format.");
     $("#"+usernameid).focus();
     return false;
     }
     */
    if ($("#pass").val() == "") {
        alert("Password can't be empty.");//密码不能为空
        //$("#message").html("Password can't be empty.");
        $("#pass").focus();
        $(":submit").attr("disabled", false);
        return false;
    }
    return true;
}

//登录成功处理
function LoginSuccess(postUrl, postData, renderUrl) {
    $.ajax({
        type: "POST",
        url: postUrl,
        data: postData,
        //async: false,
        beforeSend: function () {
            $("#message").html("loading...");
        },
        error: function (request) {
            alert("Connection error");
        },
        success: function (msg) {
            alert('Data saved: ' + msg);
            //判断输入是否成功，成功则跳转
            if ("" == msg) {
                alert('aa1');
                //document.myForm.submit();
            }
            else {
                window.location.href = renderUrl;
                //$("#message").html(decodeURI(msg));    
            }
        }
    });
}
/************login end*******************************/